package com.bjSoft.regressionTestTool.config;

import java.io.File;
import java.io.IOException;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;

import com.bjSoft.regressionTestTool.util.ArquivoEntrada;
import com.bjSoft.regressionTestTool.util.ArquivoSaida;
import com.bjSoft.regressionTestTool.Activator;
public class ConfigFileHandler {
	
	
	
	public static void readConfigFile(IWorkspaceRoot root) throws IOException {
		IPath path = new Path(".coverageconf");
		IFile config = root.getFile(path);
		if (!config.exists()) {
			File conf = config.getLocation().toFile();
			conf.createNewFile();
			writeConfigFile(root);
		} else {
			String workspacePath = root.getLocation().toOSString();
			ArquivoEntrada arq = new ArquivoEntrada(workspacePath + "\\.coverageconf");
			Activator.instrumentToolLocation = arq.readString();
			Activator.executionToolLocation = arq.readLine();
			Activator.reportToolLocation = arq.readLine();
			Activator.eclipseLocation = arq.readLine();
			arq.close();			
		}
	}
	
	public static void writeConfigFile(IWorkspaceRoot root) {
		/*
		 * instrumentTool
		 * executionTool
		 * reportTool
		 * eclipseLocation
		 */
		String projectPath = root.getLocation().toOSString();
		ArquivoSaida arq = new ArquivoSaida(projectPath + "\\.coverageconf" );
		arq.println(Activator.instrumentToolLocation);
		arq.println(Activator.executionToolLocation);
		arq.println(Activator.reportToolLocation);
		arq.println(Activator.eclipseLocation);
		arq.close();	
	}
}
